﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Data.SqlClient;
using sscore;

namespace DM4
{
    public partial class DM4
    {
        public XMLInfo GetSessionsList(string sessionsId)
        {
            BeginFunction("GetSessionsList");

            OperationResult opResult = GetUserIdBySession(sessionsId);
            XMLInfo xi = new XMLInfo(opResult);

            if (!opResult)
            {
                WriteLog(opResult.Message, MessageType.Error);
                return xi;
            }

            const string sql = "SELECT [sess_id] FROM [sessions] ORDER BY [sess_start_time] DESC";
            WriteDebugLog(sql);

            try
            {
                SqlCommand sel = new SqlCommand(sql, _conn);
                using (SqlDataReader reader = sel.ExecuteReader())
                {
                    WriteLog("Get sessions list operation complete");
                    xi.Load(reader, "sessions");
                }
            }
            catch (Exception ex)
            {
                WriteLog(ex.Message, MessageType.Error);
            }

            EndFunction("GetSessionsList");
            return xi;
        }
    }
}
